package com.glory.cqaospda.viewmodel

import com.glory.cqaospda.bean.CheckBoxList
import com.glory.cqaospda.bean.MaterialListBean
import com.glory.cqaospda.model.TaskRepository
import com.glory.mvvmnet.base.BaseViewModel
import com.glory.mvvmnet.entity.CallObserveBean
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils

class MaterialReplaceModel:BaseViewModel() {


    private val repository by lazy { TaskRepository() }

    fun defaultEqpMaterials(eqpID: String) {
        val map = JsonObject()
        map.addProperty("EquipmentName", eqpID)
        launchOnlyResult({
            val defaultEqpMaterials =
                repository.defaultEqpMaterials(map,"EMS_EqpMaterials")
            defUI.callObserve.value = CallObserveBean(1,defaultEqpMaterials)
        })
    }

    fun defaultGetBaseConfig(){

        val map = JsonObject()
        map.addProperty("GroupID", "material_type")

        launchOnlyResult({
            val baseConfigBean =
                repository.defaultGetBaseConfig(map,"EMS_GetBaseConfig")
            defUI.callObserve.value = CallObserveBean(2,baseConfigBean)
        })
    }

    fun defaultEquipmentConversion(materialList: ArrayList<MaterialListBean>,lotID:String, checkBoxList : ArrayList<CheckBoxList>, eqpid:String, remark:String, buyoff:String,keifeTemp:String) {
        val map = JsonObject()
        map.addProperty("LotNo",lotID)
        map.addProperty("StepName","")
        map.addProperty("EquipmentName",eqpid)
        map.addProperty("Remark",remark)
        map.addProperty("BuyoffFlag",buyoff)
        map.addProperty("KnifeTemp",keifeTemp)
        map.addProperty("ConversionType","MaterialChange")
        map.add("MaterialList", JsonParser().parse(Gson().toJson(materialList)).asJsonArray)
        map.add("MaintenanceItemList", JsonParser().parse(Gson().toJson(checkBoxList)).asJsonArray)

        launchOnlyResult({
            repository.defaultEquipmentConversion(map,"EMS_EquipmentConversion")
            defUI.callObserve.value = CallObserveBean(4)
        })
    }

}